﻿using System.IO;

/// <summary>
/// 浮点型的
/// </summary>
public class PropSetField : FieldBase
{
    public PropSetField(string className, string desc, string type, string name)
        : base(className, desc, type, name) { }

    public override string F_Type { get { return "PropSet"; } }

    /// <summary>
    /// 写入GUI
    /// </summary>
    public override void WriteGUI(int indentLevel, StreamWriter SW)
    {
        string e = GetIndent(indentLevel);
        SW.WriteLine();
        SW.WriteLine(e + "if (null == data.{0}) ReflectionTools.SetNonPublicField(data, \"_{1}\", new PropSet());".SafeFormat(F_Name, F_Name));
        SW.WriteLine();
        SW.WriteLine(e + "if ((data.{0}[0] = (EditorGUILayout.Foldout(data.{1}[0] != 0, \"{2}({3})\") ? 1f : 0f)) != 0)".SafeFormat(F_Name, F_Name, F_Desc, F_Name));
        SW.WriteLine(e + "{");
        SW.WriteLine(e + "    for (int i = 1; i < data.{0}.Count; ++i)".SafeFormat(F_Name));
        SW.WriteLine(e + "    {");
        SW.WriteLine(e + "        data.{0}[i] = EditorGUILayout.FloatField(((PropType)i).ToString(), data.{1}[i]);".SafeFormat(F_Name, F_Name));
        SW.WriteLine(e + "    }");
        SW.WriteLine(e + "}");
        SW.WriteLine();
    }

    /// <summary>
    /// 写入获取数据代码
    /// </summary>
    public override void WriteGetData(int indentLevel, StreamWriter SW, bool isEnd)
    {
        string endStr = isEnd ? string.Empty : ",";
        SW.WriteLine(GetIndent(indentLevel) + "PropSet.AnalysisStr(eReader.GetData(i, \"{0}\")){1} // {2}".SafeFormat(F_Name, endStr, F_Desc));
    }

    public override string ExportDataStr()
    {
        return "data.{0}.ToString()".SafeFormat(F_Name);
    }
}
